<template>
    <div>
        <h3>添加</h3>
        <table>
            <tbody>
                <tr>
                    <td>券类型</td>
                    <td>
                        <input type="text" v-model="arr.disCountType" />
                    </td>
                </tr>
                <tr>
                    <td>代金券标题</td>
                    <td>
                        <input type="text" arr.disCountTiTle />
                    </td>
                </tr>
                <tr>
                    <td>图片</td>
                    <td>
                        <input type="file" @change="Page" />
                        <img :src="arr.img" height="100" width="100" v-if="arr.img != ''" />
                    </td>
                </tr>
                <tr>
                    <td>剩余库存</td>
                    <td>
                        <input type="text" v-model="arr.shengYuNum" />
                    </td>
                </tr>
                <tr>
                    <td>每人限领</td>
                    <td>
                        <input type="text" v-model="arr.xianLingNum" />
                    </td>
                </tr>
                <tr>
                    <td>条件</td>
                    <td>
                        <input type="text" v-model="arr.tiaoJian" />
                    </td>
                </tr>
                <tr>
                    <td>减免金额</td>
                    <td>
                        <input type="text" v-model="arr.money" />
                    </td>
                </tr>
                <tr>
                    <td>有限期</td>
                    <td>
                        <input type="date" v-model="arr.disCountTime" />
                    </td>
                </tr>
                <tr>
                    <td>电话</td>
                    <td>
                        <input type="text" v-model="arr.phone" />
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <input type="button" value="添加" @click="Ok" class="btn btn-info" />
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { reactive, ref, onMounted } from 'vue';
import axios from 'axios';
import { useRoute, useRouter } from 'vue-router';

let use = useRouter();

let arr: any = reactive({
    "disCountType": "",
    "disCountTiTle": "",
    "img": "",
    "shengYuNum": "",
    "xianLingNum": "",
    "tiaoJian": "",
    "money": "",
    "disCountTime": "",
    "phone": "",
    "isDelete": true
});

const Ok = () => {
    axios({
        url: "https://localhost:7151/api/DisCount/Add",
        data: arr,
        method: "post"
    })
        .then(res => {
            if (res.data > 0) {
                alert("添加成功");
                use.push('/Show');
            }
            else {
                alert("添加失败");
            }
        })
}




const Page = (e: any) => {

    let obj = e.target.files[0];
    let f = new FormData();
    f.append("file", obj);


    axios({
        url: "https://localhost:7151/api/Img/imgs",
        method: "post",
        data: f
    })

        .then(res => {

            arr.img = res.data;


        })
}

</script>

<style scoped></style>